package com.sjtu.rest;

import com.sjtu.config.Admin;
import com.sjtu.config.AdminHandlerFilter;
import com.sjtu.feign.ClientInfoFeign;
import com.sjtu.feign.UserAccountFeign;
import com.sjtu.web.BaseRest;
import com.sjtu.web.Result;
import com.sjtu.web.form.ClientInfoForm;
import com.sjtu.web.search.ClientInfoSearch;
import com.sjtu.web.vo.ClientInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 接入服务的子系统信息相关
 * nerine
 * 1/29/2020
 */
@RequestMapping("/admin/client-info")
@RestController
public class ClientInfoRest extends BaseRest {
    @Autowired
    private ClientInfoFeign clientInfoFeign;
    @Autowired
    private UserAccountFeign userAccountFeign;

    @Admin
    @PostMapping("/list")
    public Result<?> list(@RequestHeader(AdminHandlerFilter.OPERATOR_ID) String operatorId,
                          @Valid @RequestBody ClientInfoSearch search) {
        return clientInfoFeign.list(search);
    }

    @Admin
    @PostMapping("/save")
    public Result<?> save(@RequestHeader(AdminHandlerFilter.OPERATOR_ID) String operatorId,
                          @RequestBody @Valid ClientInfoForm form) {
        form.setOperatorId(operatorId);
        return clientInfoFeign.save(form);
    }
    @Admin
    @GetMapping("/detail/{id}")
    public Result<ClientInfoVo> detail(@PathVariable String id) {
        return clientInfoFeign.detail(id);
    }
}
